package org.msg.commons;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Create by bo.chen in 2018/10/13 上午11:12
 */
public final class InstructUtils {

    private final static String INSTRUCT_PATTERN = "([^\\s]+)\\s+(.*)";

    public static boolean doub(String message) {
        Pattern pattern = Pattern.compile(INSTRUCT_PATTERN);
        Matcher matcher = pattern.matcher(message);
        return matcher.matches();
    }

    /**
     * 取第一个空格前的字符串
     */
    public static final String getInstruct(String message) {
        return message.trim().replaceAll(INSTRUCT_PATTERN,"$1");
    }

    /**
     * 取第一个空格后的字符串
     */
    public static final String getParams(String message) {
        return message.trim().replaceAll(INSTRUCT_PATTERN,"$2");
    }

    public static void main(String[] args) {
        System.out.println(getInstruct("in fee fef fdsfdsf fsf"));

        System.out.println(getParams("in fee fe"));

        Multimap<String, String> multimap = ArrayListMultimap.create();
        multimap.put("1","1");
        multimap.put("1","1");
        multimap.put("1","1");
        multimap.put("1","1");
        multimap.put("1","1");
        multimap.keySet().forEach(k -> {
            System.out.println(k);
        });
    }

}